{% form_theme form '::fields2tab.html.twig' %}
<div class="contentwrapper">
    <div class="heading">
        <h3>Nouveau Caisse</h3>
    </div>
    <div class="row-fluid">
        <div class="span12">
            <form id="form_caisse" action="" {{ form_enctype(form) }} method="POST" class="form-horizontal seperator">
                    {{ form_row(form.code,{'attr':{'readonly':'readonly'}}) }}
                {{ form_row(form.libelle) }}
                    {% if(is_granted('ROLE_SUPER_ADMIN')) %}
                    {{form_row(form.departement)}}
                    {% else %}
                    <input type="hidden" id="gds_ventebundle_caissetype_departement" value="{{app.user.departement.id}}" name="gds_ventebundle_caissetype[departement]"/>
                    {% endif %}
                    {{ form_row(form._token) }}
                    <div style="float: left;width: 90%" class="form-actions">
                        <button onclick="saveCaisse('n')" class="btn btn-info" type="button">Enregistrer et Nouveau</button>
                        <button onclick="saveCaisse('f')" class="btn btn-info" type="button">Enregistrer et Fermer</button>
                        <button onclick="listCaisse()" class="btn" type="button">Retour vers liste</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script>
                            
                            function saveCaisse(red) {
                                var data = $('#form_caisse').serialize()
                                if ($('#form_caisse').valid()) {
                                    $.ajax({
                                        type: 'post',
                                        url: '{{ path('gds_caisse_new') }}',
                                        data: data + '&red=' + red,
                                        success: function(data) {
                                            $('#div_caisse').html(data)
                                        }
                                    })
                                }
                            }
                            function listCaisse() {
                                $.ajax({
                                    type: 'post',
                                    url: '{{ path('gds_caisse_list') }}',
                                    success: function(data) {
                                        $('#div_caisse').html(data)
                                    }
                                })
                            }
        </script>